package slideWindow;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class lengthOfLongestSubstring {
    public static int lengthOfLongestSubstring(String str){
            int i=0;
            int j=0;
            int result=0;
            int n=str.length();
            Set<Character>set=new HashSet<>();
            while (i<n&&j<n){
                if (!set.contains(str.charAt(j))){
                    set.add(str.charAt(j));
                    j++;
                    result=Math.max(j-i,result);
                }
                else{
                    set.remove(str.charAt(i));
                    i++;
                }
            }
            return result;
        }

    public static void main(String[] args) {
        String str="abcabcbb";
        System.out.println(lengthOfLongestSubstring(str));
    }

    }
